"use strict";
define(['jquery'], function() {
		var  yapot_emoji= function(options) {
			  var defaults = {
		  	            types:'set',
			            data_key:'key',
			            on:'li',
			            content:'',
			            parsetype:'single',
			            init_location:null,
			            dom:null,
			            position:{
					t:'0px',
					l:'0px',
				},
			            callback:function(){}
			        };
			        var o = $.extend(defaults,options);
				var obj = {
					init:function(){
						if (o.types==='set') {
							obj.onclick($(o.on));
						}else{
							obj.parseContent(o.content,o.parsetype);
						}
					},
					onclick:function(elm){
						elm.on('click','img',function(){
							return o.callback($(this).data(o.data_key));
						});
					},
					parseContent:function(content,type){
						if (content) {
							var len=0;
							var imglen=yapot_emoji_key.length;
							if (type=='array') {
								for (var i = 0 ,len =  content.length; i <len; i++) {
										content[i].comment=content[i].comment.replace(new RegExp('<','gm'),"&lt;");
										content[i].comment=content[i].comment.replace(new RegExp('>','gm'),"&gt;");
									for (var j = 0; j < imglen; j++) {
										content[i].comment=content[i].comment.replace(new RegExp('\\['+yapot_emoji_key[j].key+'\\]','gm'),yapot_emoji_key[j].value);
									};
								};
							}else{
										content=content.replace(new RegExp('<','gm'),"&lt;");
										content=content.replace(new RegExp('>','gm'),"&gt;");
									for (var j = 0; j < imglen; j++) {
										content=content.replace(new RegExp('\\['+yapot_emoji_key[j].key+'\\]','gm'),yapot_emoji_key[j].value);
									};
							}
						};
						return o.callback(content);
					},
					open:function(){
						o.init_location.append(o.dom);
						$('#comment').css('top',o.position.t+'px');
						$('#comment').css('left',o.position.l+'px');
					},
					close:function(){
						$('#comment').remove();
					}
				};
			return obj;
		}
  	  return yapot_emoji;
});




